
import time
import hashlib

def sleep(n_secs):
    time.sleep(n_secs)
def sign_body(body,appkid="12345"):
    """请求body生成sign"""
    a = ["".join(i) for i in body.items() if i[1] and i[0] != "sign"]
    """排序"""
    strA = "".join(sorted(a))
    StrSingTmp = strA+appkid

    """md5加密"""
    def jiamimd5(src):
        m = hashlib.md5()
        m.update(src.encode('UTF-8'))
        return m.hexdigest()
    sign = jiamimd5(StrSingTmp.lower())
    print(sign)
    return sign
def setup_request(request):
    """setuphook函数预处理签名"""
    body = request.get("json")
    print(body)
    signe = sign_body(body,appkid="12345")
    print(signe)
    request["json"]["sign"]
if __name__ == '__main__':
    body = {
        "username": "test",
        "password": "123456"
    }
    print(sign_body(body))